package com.pd.dao.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by dong peng on 2018/3/31.
 */
public class DataSourceContextHold {

    private static Logger log = LoggerFactory.getLogger(DataSourceContextHold.class);

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    // 设置数据源
    public static void setType(String type) {
        if(log.isInfoEnabled()) {
            log.info("==================切换数据源, 类型:"+type+"===========");
        }
        contextHolder.set(type);
    }

    public static String getType() {
        return contextHolder.get();
    }

    // 清除数据源类型
    public static void clearType() {
        contextHolder.remove();
    }

}
